package com.yunyan.util.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.yunyan.entity.HistoryData;
import com.yunyan.entity.SchoolData;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SchoolListener extends AnalysisEventListener<SchoolData> {


    private List<SchoolData> dataList = new ArrayList<>();

    private Set<String> codeSet = new HashSet<>();

    private volatile boolean finished = false;
    @Override
    public void invoke(SchoolData rankData, AnalysisContext context) {
        ReadRowHolder readRowHolder = context.readRowHolder();
        int rowIndex = readRowHolder.getRowIndex();
        if(rowIndex < 5) {
            // 忽略
            return;
        }
        if (!codeSet.contains(rankData.getId())) {
            codeSet.add(rankData.getId());
            dataList.add(rankData);
        }

    }

    public List<SchoolData> getDataList() {
        while (!finished) {

        }
        return dataList;
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        finished = true;
    }
}